<template>
  <div style="width:100%">
    <span style="float:left">
      <span v-if="updateTime">数据刷新于{{ lastTime }}秒前</span>
        <span v-else>请先登录</span>
      </span>
      <span style="float:right">
        成都终端管制室创新工作室 @{{ new Date().getFullYear() }}
    </span>
  </div>
</template>

<script>
  export default {
    computed: {
      updateTime() {
        return this.$store.state.updateTime;
      },
    },
    methods: {
      calcLastTime() {
        if (!this.updateTime) return "";
        return Math.floor(
          (new Date().getTime() - this.$store.state.updateTime.getTime()) / 1000
        );
      },
    },
    data() {
      return {
        lastTime: "",
      };
    },
    mounted() {
      let self = this;
      setInterval(() => {
        self.lastTime = self.calcLastTime();
      }, 1000);
    },
  };
</script>